package cc.orange.mainView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;
import cc.orange.BuildConfig;
import cc.orange.R;
import cc.orange.databinding.ActivityMainA21Binding;
import demo.smart.access.xutlis.util.ZXSharedPrefUtil;

import android.os.Bundle;
import android.view.View;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

public class MainA21Activity extends AppCompatActivity implements View.OnClickListener{

    private List<Fragment> fragments=new ArrayList<>();
    private ActivityMainA21Binding binding;
    private MyFragmentAdapet myFragmentAdapet;
    private ZXSharedPrefUtil sharedPrefUtil;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main_a21);
        sharedPrefUtil = new ZXSharedPrefUtil();
        initViews();
    }

    private void initViews() {
        initTab(1);
        binding.homeRel2.setOnClickListener(this);
        binding.homeRel3.setOnClickListener(this);
        binding.homeRel1.setOnClickListener(this);
        fragments.add(new A12MsgListFragment());
        fragments.add(new FaceA1ListFragment());
        fragments.add(new A12SetFragment());

        myFragmentAdapet=new MyFragmentAdapet(MainA21Activity.this,fragments);
        binding.homeFramel.setAdapter(myFragmentAdapet);
        binding.homeFramel.setOffscreenPageLimit(3);
        binding.homeFramel.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                initTab(position);
            }
        });
        binding.homeFramel.setCurrentItem(1);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.home_rel2:
                initTab(1);
                break;
            case R.id.home_rel3:
                initTab(2);
                break;
            case R.id.home_rel1:
                initTab(0);
                break;
        }
    }


    private void initTab(int type){

        if (BuildConfig.UIA.equals("A1")) {// A1面
            binding.homeBackRel1.setBackgroundColor(getResources().getColor(R.color.color_f7));
            binding.homeBackRel1.setBackgroundResource(0);
            binding.homeRel2.setBackgroundResource(type == 1 ? R.drawable.shape_a2_hometab_back : R.color.white);
            binding.homeRel1.setBackgroundResource(type == 0 ? R.drawable.shape_a2_hometab_back : R.color.white);
            binding.homeRel3.setBackgroundResource(type == 2 ? R.drawable.shape_a2_hometab_back : R.color.white);

            binding.homeImg1.setImageResource(type == 0 ? R.drawable.icon_a21_img3_c : R.drawable.icon_a21_img3_d);
            binding.homeImg2.setImageResource(type == 1 ? R.drawable.icon_a21_img_c : R.drawable.icon_a21_img1_d);
            binding.homeImg3.setImageResource(type == 2 ? R.drawable.icon_a21_img2_d : R.drawable.icon_a21_img2_c);
        }else if (BuildConfig.UIA.equals("A2")){// A2面
            binding.homeBackRel1.setBackgroundColor(getResources().getColor(R.color.color_f7));
            binding.homeBackRel1.setBackgroundResource(0);
            binding.homeRel2.setBackgroundResource(type == 1 ? R.drawable.shape_a22_hometab_back : R.color.white);
            binding.homeRel1.setBackgroundResource(type == 0 ? R.drawable.shape_a22_hometab_back : R.color.white);
            binding.homeRel3.setBackgroundResource(type == 2 ? R.drawable.shape_a22_hometab_back : R.color.white);

            binding.homeImg1.setImageResource(R.drawable.icon_a21_img3_d);
            binding.homeImg2.setImageResource(R.drawable.icon_a21_img1_d);
            binding.homeImg3.setImageResource(R.drawable.icon_a21_img2_c);
        }else if(BuildConfig.UIA.equals("A5")){
            binding.homeBackRel1.setBackgroundColor(0);
            binding.homeBackRel1.setBackgroundResource(R.drawable.icon_a5_backimg1);

            binding.homeRel2.setBackgroundResource(0);
            binding.homeRel1.setBackgroundResource(0);
            binding.homeRel3.setBackgroundResource(0);

            binding.homeImg1.setImageResource(type == 0 ? R.drawable.icon_a5_img3_c : R.drawable.icon_a5_img3_d);
            binding.homeImg2.setImageResource(type == 1 ? R.drawable.icon_a5_img_c : R.drawable.icon_a5_img_d);
            binding.homeImg3.setImageResource(type == 2 ? R.drawable.icon_a5_img2_c : R.drawable.icon_a5_img2_d);
        }
        binding.homeFramel.setCurrentItem(type);
    }
}